#include "FAlpCheckBtn.h"

CFAlpCheckBtn::CFAlpCheckBtn(UINT nID):CFAlpResBtn(nID)
{
	Init();
}

CFAlpCheckBtn::CFAlpCheckBtn(wstring strCaption,UINT nID)
:	CFAlpResBtn(strCaption,nID)
{
	Init();
}

CFAlpCheckBtn::CFAlpCheckBtn(DWORD dwStyle,wstring strCaption, const CRect &rc, UINT nID)
:	CFAlpResBtn(dwStyle, strCaption,rc, nID)
{
	Init();
}

CFAlpCheckBtn::CFAlpCheckBtn(DWORD dwStyle, wstring strCaption, int x, int y, int cx, int cy, UINT nID)
:	CFAlpResBtn(dwStyle, strCaption, x, y, cx, cy, nID)
{
	Init();
}

CFAlpCheckBtn::~CFAlpCheckBtn(void)
{

}

void CFAlpCheckBtn::Init()
{
	m_bChecked = FALSE;
}

void CFAlpCheckBtn::SetChecked(BOOL bChecked)
{
	m_bChecked = bChecked;
}

BOOL CFAlpCheckBtn::IsChecked()
{
	return m_bChecked;
}


void CFAlpCheckBtn::Paint(CDC* pDC)
{
	if(m_rcControl.IsRectEmpty())	
		return ;
	
	if(!IsVisible())
		return;
	
}

void	CFAlpCheckBtn::ImprovePaint( HANDLE hDB ,HDC hdc )
{
	if(m_rcControl.IsRectEmpty())
		return ;
	
	if(!IsVisible())
		return;
	if ( m_pBtnAlpRes[STBTN_NOR]==NULL )
		return ;
	
	CFAlphaRes* pRes = m_pBtnAlpRes[STBTN_NOR];
	if ( m_bChecked && NULL!=m_pBtnAlpRes[STBTN_ACT] )
		pRes = m_pBtnAlpRes[STBTN_ACT];	

	FASTBLTALPHABPP( pRes, hDB,m_rcControl.TopLeft(),GetConBKSize() );
	PaintCaption( hdc );

}

void  CFAlpCheckBtn::Click(DWORD dwClick, POINT pt)
{
	if ( !IsEnabled() || !IsVisible() || m_rcControl.IsRectEmpty() )
		return;

	if ( dwClick&CLICK_DOWN ){
		PlaySound( m_strBtnWav.c_str(), NULL, SND_FILENAME|SND_ASYNC|SND_NODEFAULT );
		SetState( STATE_PUSHED ); 
		RSetBtnState( STBTN_ACT );

		if ( m_pContainer!=NULL && IsWindow( m_pContainer->m_hWnd) )
			::SendMessage( m_pContainer->m_hWnd,WM_COMMAND,GetID(),NULL);

	}
	else if ( dwClick&CLICK_UP ){
		SetState( STATE_NORMAL ); 
		RSetBtnState( STBTN_NOR );
	}
	else{
		RSetBtnState( STBTN_NOR );	
	}

	//if ( m_pContainer!=NULL && IsWindow( m_pContainer->m_hWnd) )
	//{
	//	//CClientDC ClientDC( m_pContainer->m_hWnd );
	//	//CContainer *pImpCon = (CImproveCon *)m_pContainer;
	//	//pImpCon->Paint( &ClientDC,m_rcControl );

	//	InvalidateRect( m_pContainer->m_hWnd,m_rcControl,FALSE );
	//	UpdateWindow( m_pContainer->m_hWnd );
	//}
	//if ( dwClick&CLICK_UP && GetRect().PtInRect( pt ) )
	
}